package cn.yl.order.server.adapter;

import cn.yl.order.server.entity.PayOrderRecord;
import cn.yl.order.server.service.PayOrderRecordService;
import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// 2个消费者
@Component
@Slf4j
public class WorkReceiveListener {
    @Autowired
    private PayOrderRecordService payOrderRecordService;
    @RabbitListener(queues = "pay_order_record_work")
    public void receiveMessage(String msg, Channel channel, Message message) {
        // 只包含发送的消息
        PayOrderRecord payOrderRecord = JSON.parseObject(msg, PayOrderRecord.class);
        log.info("标记");
        log.info("payOrderRecord:{}", payOrderRecord);
        payOrderRecordService.save(payOrderRecord);
        log.info("添加日志");
        // channel 通道信息
        // message 附加的参数信息
    }

    @RabbitListener(queues = "pay_order_record_work")
    public void receiveMessage2(String payOrderRecordString, Channel channel, Message message) {
        // 包含所有的信息
//        PayOrderRecord payOrderRecord = (PayOrderRecord) SerializationUtils.deserialize(bs);
        PayOrderRecord payOrderRecord = JSON.parseObject(payOrderRecordString, PayOrderRecord.class);
        log.info("标记");
        log.info("payOrderRecord:{}", payOrderRecord);
        payOrderRecordService.save(payOrderRecord);
        log.info("添加日志");
//        System.out.println("2---接收到消息：" + obj);
    }
}
